<?xml version="1.0" encoding="ISO-8859-1" ?>

<html xmlns="http://www.w3.org/1999/xhtml" 
	  xmlns:h="http://java.sun.com/jsf/html" 
	  xmlns:f="http://java.sun.com/jsf/core"
	  xmlns:c="http://java.sun.com/jsp/jstl/core"
	  xmlns:p="http://primefaces.org/ui"
	  xmlns:ui="http://java.sun.com/jsf/facelets"
	  xmlns:func="http://ucblive.com/functions">

<h:head>

</h:head> 

<h:body>
	<ui:composition template="/template.xhtml">
		<ui:define name="conteudo">
			<center>
				<h:form>	
					<p:growl id="messages" />  
				 	<p:panel id="painelPost" styleClass="classTextLeft painelPostagens" style="width: 65%; float:left;"
				 			 rendered="#{topicoManagedBean.topico.idTopico!=0}">
			  	    	<f:facet name="header">
			  	    		<h:outputLabel value="#{topicoManagedBean.topico.titulo}" />
			  	    		<p:commandLink immediate="true" action="#{topicoManagedBean.cadastraTopico}" rendered="#{(loginManagedBean.usuario.tipo==1 or loginManagedBean.usuario.tipo==2)}">
  	    						<h:graphicImage value="/img/editar.png" title="#{msg.editarTopico}" />
  	    						<f:setPropertyActionListener value="true" target="#{topicoManagedBean.topicoAlterado}" />
  	    					</p:commandLink>
			  	    		<p:commandLink onclick="confirmacaoTopico.show();" rendered="#{(loginManagedBean.usuario.tipo==1 or loginManagedBean.usuario.tipo==2)}">
  	    						<h:graphicImage value="/img/excluir.png" title="#{msg.excluirTopico}" />
  	    					</p:commandLink>
			  	    	</f:facet>  
			  	    				   
			  	    	<p:dataList value="#{topicoManagedBean.postagens}" var="postagem" itemType="none"
			  	    				paginator="true" paginatorPosition="top" rows="10" pageLinks="5"
			  	    				rendered="#{not empty topicoManagedBean.postagens}" styleClass="zerarLista">
			  	    		<p:panelGrid style="width: 100%;">
				  	    		<f:facet name="header">
				  	    			<p:row>
				  	    				<p:column colspan="3" styleClass="classTextLeft">
				  	    					<h:outputLabel value="#{msg.autor}: #{postagem.usuario.login}" />
				  	    					<p:commandLink onclick="confirmacaoPostagem.show();" immediate="true" rendered="#{func:podeExcluirPostagem(topicoManagedBean.usuarioLogin,postagem)}">
				  	    						<f:setPropertyActionListener target="#{topicoManagedBean.postagem}" value="#{postagem}"/>
				  	    						<h:graphicImage value="/img/excluir.png" title="#{msg.excluirPostagem}" />
				  	    					</p:commandLink>
				  	    					<h:commandLink actionListener="#{topicoManagedBean.editarPostagem}" immediate="true" rendered="#{func:podeEditarPostagem(topicoManagedBean.usuarioLogin,postagem)}">
				  	    						<f:attribute name="postagem" value="#{postagem}"/>
				  	    						<h:graphicImage value="/img/editar.png" title="#{msg.editarPostagem}" />
				  	    					</h:commandLink>
				  	    					<h:commandLink actionListener="#{topicoManagedBean.responderPostagem}" immediate="true">
				  	    						<f:attribute name="postagemPai" value="#{postagem}"/>
				  	    						<h:graphicImage value="/img/lapis.png" title="#{msg.responder}" />
				  	    					</h:commandLink>
				  	    					<h:commandLink actionListener="#{usuarioManagedBean.adicionaWarns}" immediate="true" 
				  	    					rendered="#{(loginManagedBean.usuario.tipo==1 or loginManagedBean.usuario.tipo==2) and postagem.usuario.tipo==3 and postagem.usuario.qtdWarns!=7}">
				  	    						<f:attribute name="usuario" value="#{postagem.usuario}"/>
				  	    						<h:graphicImage value="/img/warn.png" title="#{msg.adicionarWarns}"/>
				  	    					</h:commandLink>	
				  	    					<p:outputLabel value=" #{postagem.usuario.qtdWarns} warn" rendered="#{(loginManagedBean.usuario.tipo==1 or loginManagedBean.usuario.tipo==2) and postagem.usuario.tipo==3}"/>			  	    					
				  	    					<p:calendar styleClass="inputCalendar" value="#{postagem.dataCriacao}" disabled="true"
				  	    								pattern="dd/MM/yyyy HH:mm"/>
				  	    				</p:column>			  	    				
				  	    			</p:row>
				  	    		</f:facet>
				  	    		<p:row>
					  	    		<p:column>
					  	    			<p:dataList value="#{func:postagensAnteriores(postagem)}" var="postagemAnterior" rendered="#{postagem.idPostagemPai != null}">
					  	    				<h:outputText value="#{postagemAnterior.conteudo}" escape="false"/>
					  	    				<p:separator />
					  	    			</p:dataList>
					  	    			<h:outputText value="#{postagem.conteudo}" escape="false"/>
					  	    			<h:panelGroup rendered="#{(topicoManagedBean.editPostagem and topicoManagedBean.postagem.idPostagem == postagem.idPostagem) or
					  	    									  (topicoManagedBean.respondePostagem and topicoManagedBean.postagemPai.idPostagem == postagem.idPostagem)}">
											<p:editor id="conteudo"  value="#{topicoManagedBean.postagem.conteudo}" maxlength="1500" required="true" width="420"/>
											<h:commandButton value="#{msg.cadastrar}" actionListener="#{topicoManagedBean.inserePostagem}"/>
										</h:panelGroup>
					  	    		</p:column>
					  	    		
				  	    		</p:row>
			  	    		</p:panelGrid>
			  	    		<p:separator />
			  	    	</p:dataList>

						<h:panelGroup rendered="#{!topicoManagedBean.editPostagem and !topicoManagedBean.respondePostagem}">
							<p:editor id="conteudo"  value="#{topicoManagedBean.postagem.conteudo}" maxlength="1500" required="true" width="450"/>
							<p:commandButton value="#{msg.cadastrar}" actionListener="#{topicoManagedBean.inserePostagem}" update="@form"/>
						</h:panelGroup>
								
						
			  	    </p:panel>
			  	    
					<p:panel styleClass="painelMenuTopicos">
						<f:facet name="header">
			  	    		<h:outputLabel value="#{topicoManagedBean.disciplina.nome}" />
			  	    	</f:facet>
							
		  	    		<p:dataList value="#{topicoManagedBean.topicos}" var="topico" itemType="none" 
		  	    					styleClass="contentPainelMenuTopicos classTextLeft" 
		  	    					paginator="true" paginatorPosition="top" rows="5" pageLinks="3">
			  	    		<h:commandLink value="#{topico.titulo}" actionListener="#{topicoManagedBean.populaPostagens}" immediate="true">
			  	    			<f:attribute value="#{topico}" name="topico" />
			  	    		</h:commandLink>
			  	    		
			  	    	</p:dataList>
				  	    	
			  	    	<f:facet name="footer">			  	
				  	    	<h:commandLink value="#{msg.cadastrarTopico}" action="#{topicoManagedBean.cadastraTopico}" immediate="true" rendered="#{(loginManagedBean.usuario.tipo==1 or loginManagedBean.usuario.tipo==2)}" >
				  	    		<f:setPropertyActionListener value="false" target="#{topicoManagedBean.topicoAlterado}" />
				  	    	</h:commandLink>
			  	    		<br></br>
			  	    		<h:outputLink value="#{facesContext.externalContext.request.contextPath}/alu/forumList.jsf"><p:outputLabel value="#{msg.voltar}"/> </h:outputLink>
			  	    	</f:facet>
	  	    		</p:panel>	  	    
			  	   
			  	   <div style="clear : both;" />
			  	   
			  	   <p:confirmDialog id="confirmaExclusaoTopico" message="#{msg.perguntaExclusao} #{msg.este} #{msg.minTopico}?"
														 header="#{msg.excluirTopico}" severity="alert" widgetVar="confirmacaoTopico" closable="false">
						<p:commandButton id="confirmaTopico" value="#{msg.sim}" oncomplete="confirmacaoTopico.hide()" immediate="true"
										 actionListener="#{topicoManagedBean.excluirTopico}" update="@form" />
						 <p:commandButton id="cancelaTopico" value="#{msg.nao}" onclick="confirmacaoTopico.hide()" 
										  action="#{topicoManagedBean.populaTopicos}"/>	
					</p:confirmDialog>
					
					<p:confirmDialog id="confirmaExclusaoPostagem" message="#{msg.perguntaExclusao} #{msg.esta} #{msg.minPostagem}?"
														 header="#{msg.excluirPostagem}" severity="alert" widgetVar="confirmacaoPostagem" closable="false">
						<p:commandButton id="confirmaPostagem" value="#{msg.sim}" oncomplete="confirmacaoPostagem.hide()" immediate="true"
										 actionListener="#{topicoManagedBean.excluirPostagem}" update="@form" />
						 <p:commandButton id="cancelaPostagem" value="#{msg.nao}" onclick="confirmacaoPostagem.hide()" 
										  action="#{topicoManagedBean.populaPostagens}"/>	
					</p:confirmDialog>
			  	</h:form>
			</center>
		</ui:define>
</ui:composition>
</h:body> 
</html>